﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.Models.Product>
@{
    ViewBag.Title = "主料查询";
    var productName = ViewBag.ProductName;
    var productNum = ViewBag.ProductNum;
}

<section class="content-header">
    <h1>
        主料查询
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">主料查询</li>
    </ol>
</section>

<section class="content">
    <div class="form-horizontal">
        <div class="box box-solid">
            <div class="box-nav clearfix">
                @*<div class="col-sm-12">
                    <button type="button" class="btn btn-primary" onclick="Select();" title="查询"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
                    <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                </div>*@
                <div class="col-sm-12">
                    <form action="@Url.Action("Index", "Material")" method="post">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 名称 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="ProductName" name="ProductName" value="@ViewBag.ProductName" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 编号 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="ProductNum" name="ProductNum" value="@ViewBag.ProductNum" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <button type="submit" class="btn btn-primary">查询</button>
                            <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                        </div>
                    </form>
                </div>
            </div>
            
            <div class="box-body">
                <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                    <thead>
                        <tr>
                            <th data-sort-ignore="true">
                                名称
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                编号
                            </th>

                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                创建者
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                创建时间
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                规格列表
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                状态
                            </th>
                            <th data-sort-ignore="true">
                                操作
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (null != Model)
                        {
                            foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Name)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Number)
                                    </td>

                                    <td>
                                        @Html.DisplayFor(modelItem => item.CreatorName)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.CreateTime)
                                    </td>
                                    <td>
                                        <span style="color: dodgerblue; cursor: pointer;" onclick="ShowModalFormat('@item.Id')">规格列表</span>
                                    </td>
                                    <td>
                                        @if (item.Status == 1)
                                        {
                                            <span class="bg-green btn-xs">正常</span>
                                        }
                                        else if (item.Status == -2)
                                        {
                                            <span class="bg-black btn-xs">禁用</span>
                                        }
                                    </td>
                                    <td>
                                        <span class="btn bg-blue btn-xs" onclick="ShowModal('@item.Id')">查看</span>&nbsp;&nbsp;&nbsp;&nbsp;
                                        <a class="btn bg-blue btn-xs" href="@Url.Action("MaterialEdit", "Material", new { PID = item.Id })">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;
                                        @if (item.Status == 1)
                                        {
                                            <span class="btn bg-orange btn-xs" onclick="Change('@item.Id','@item.Status')">禁用</span>
                                        }
                                        else if (item.Status == -2)
                                        {
                                            <span class="btn bg-orange btn-xs" onclick="Change('@item.Id','@item.Status')">启用</span>
                                        }
                                    </td>
                                </tr>
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                @Html.PagedListPager(Model, page => Url.Action("Index", new { page, productName, productNum }))
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</section>

<!--查询对话框-->
<div class="modal" id="queryDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查询</h4>
            </div>
            <form class="form-horizontal" action="@Url.Action("Index", "Material")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 名称 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="ProductName" name="ProductName" value="@ViewBag.ProductName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 编号 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="ProductNum" name="ProductNum" value="@ViewBag.ProductNum" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>1
    </div>
</div>

@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });

        function Select() {
            $('#queryDlg').modal();
        }

        //显示原料信息
        function ShowModal(id) {
            var options = {
                id: null,
                title: '原料信息',
                width: "100%",
                height: "100%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

        //弹窗显示规格列表
        function ShowModalFormat(id) {
            var options = {
                id: null,
                title: '原料规格',
                width: "100%",
                height: "100%",
                url: "../Material/MaterialFormat?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

        function Change(id, status) {
            var str = "确定禁用吗？";
            if (status == '-2') {
                str = "确定启用吗？";
            }

            top.layer.confirm(str, {
                icon: "fa-exclamation-circle",
                title: "系统提示",
                btn: ['确认', '取消'],
                btnclass: ['btn btn-primary', 'btn btn-danger'],
            }, function () {
                $.ajax({
                    url: "/Material/ProChange",
                    type: "Post",
                    data: { id: id },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        location.reload();
                    }
                });
            }, function () {

            });
        }
    </script>
}